package com.wwy.arithmetic.newsuanfa;

import sun.awt.image.ImageWatched;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author 王伟羽
 * @program: arithmetictest
 * @description:
 * @create: 2025/03/31
 */

public class Youxiaokuohao {
    public boolean isValid(String s) {
        if(s==null||s==""){
            return false;
        }
        char[] chars = s.toCharArray();
        Deque<Character> deque = new LinkedList<>();
        for (Character character : chars) {
            if(character=='{'){
                deque.push('}');
            }else if (character=='['){
                deque.push(']');
            }
            else if (character=='('){
                deque.push(')');
            }else if(deque.isEmpty()||character.equals(deque.pop())){
                return false;
            }
        }
        return deque.isEmpty();
    }
}
